using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;

using System.Data;

namespace Business
{
    public class ChiTietHoaDonService
    {




		//////////////////////////////////////////////////////////

 		                                                         

		//            Enter code your here                      //

		                                                         

		//////////////////////////////////////////////////////////

       static public DataTable ConvertListChiTietHoaDonDTOToDataTable( List<ChiTietHoaDonDTO> lst)
       {
               DataTable dt = new DataTable();
           dt.Columns.Add( "MaChiTietHoaDon");
           dt.Columns.Add( "MaHoaDon");
           dt.Columns.Add( "MaPhieuThue");
           dt.Columns.Add( "ThanhTien");
           for( int i = 0; i < lst.Count; i ++)
           {
               dt.Rows.Add(
                       lst[i].MaChiTietHoaDon,      
                       lst[i].MaHoaDon,      
                       lst[i].MaPhieuThue,      
                       lst[i].ThanhTien      
                   );
           }
               return dt;
       }
        static public int GetIdentity()
        {
            Data.ChiTietHoaDonRepository repo = new ChiTietHoaDonRepository();
            return repo.GetIdentity();
        }

        static public int Count()
        {
            return ChiTietHoaDonRepository.Count();
        }
        public static bool Them(ChiTietHoaDonDTO objDTO)
        {
                ChiTietHoaDonRepository repo = new ChiTietHoaDonRepository();
                return repo.Them(objDTO);
        }

        public static bool Xoa(int MaChiTietHoaDon, bool XoaKhoaNgoai=false)
        {
              ChiTietHoaDonRepository Repo = new ChiTietHoaDonRepository();
              return Repo.Xoa(MaChiTietHoaDon,XoaKhoaNgoai);
        }

        public static void CapNhat(ChiTietHoaDonDTO objDTO)
        {
            try
            {
                ChiTietHoaDonRepository Repo = new ChiTietHoaDonRepository();
                Repo.CapNhat(objDTO);
            }
            catch (System.Exception )
            {
            }
        }

        public static List<ChiTietHoaDonDTO> LayDanhSach()
        {
            List<ChiTietHoaDonDTO> lst = new List<ChiTietHoaDonDTO>();
            try
            {
                ChiTietHoaDonRepository obj = new ChiTietHoaDonRepository();
                lst = obj.LayDanhSach();
            }
            catch (System.Exception )
            {
            }
            return lst;
        }

        static public List<ChiTietHoaDonDTO> LayDanhSach(int Start, int Record)
        {
             Data.ChiTietHoaDonRepository repo = new ChiTietHoaDonRepository();
            return repo.LayDanhSach(Start, Record);
        }

        public static ChiTietHoaDonDTO LayTheoMa(int MaChiTietHoaDon)
        {
            ChiTietHoaDonDTO objDTO = new ChiTietHoaDonDTO();
            try
            {
                ChiTietHoaDonRepository Repo = new ChiTietHoaDonRepository();
                objDTO = Repo.LayTheoMa(MaChiTietHoaDon);
            }
            catch (System.Exception )
            {
            }
            return objDTO;
        }

//
//Khoa ngoai HoaDon
//
        static public List<ChiTietHoaDonDTO> LayDanhSachTheoMaHoaDon( int MaHoaDon)
        {
             Data.ChiTietHoaDonRepository repo = new ChiTietHoaDonRepository();
            return repo.LayDanhSachTheoMaHoaDon( MaHoaDon);
        }

        static public void XoaTheoMaHoaDon( int MaHoaDon, bool XoaKhoaNgoai=false)
        {
             Data.ChiTietHoaDonRepository repo = new ChiTietHoaDonRepository();
            repo.XoaTheoMaHoaDon( MaHoaDon,XoaKhoaNgoai);
        }


//
//Khoa ngoai PhieuThue
//
        static public List<ChiTietHoaDonDTO> LayDanhSachTheoMaPhieuThue( int MaPhieuThue)
        {
             Data.ChiTietHoaDonRepository repo = new ChiTietHoaDonRepository();
            return repo.LayDanhSachTheoMaPhieuThue( MaPhieuThue);
        }

        static public void XoaTheoMaPhieuThue( int MaPhieuThue, bool XoaKhoaNgoai=false)
        {
             Data.ChiTietHoaDonRepository repo = new ChiTietHoaDonRepository();
            repo.XoaTheoMaPhieuThue( MaPhieuThue,XoaKhoaNgoai);
        }

    }
}

